import fetch from 'common/src/utils/fetch';

/**
 * 课程列表查询
 */
export function queryCourseList(data) {
    return fetch({
        url: '/api/cultureservice/minorCourse/queryCourseList',
        method: 'POST',
        data
    });
}

/**
 * 课程新增
 */
export function addCourse(data) {
    return fetch({
        url: '/api/cultureservice/minorCourse/addCourse',
        method: 'POST',
        data
    });
}

/**
 * 课程修改
 */
export function updateCourse(data) {
    return fetch({
        url: '/api/cultureservice/minorCourse/updateCourse',
        method: 'POST',
        data
    });
}

/**
 * 课程删除
 */
export function deleteCourse(data) {
    return fetch({
        url: '/api/cultureservice/minorCourse/deleteCourse',
        method: 'POST',
        data
    });
}

/**
 * 课程信息查询
 */
export function queryCourseInfo(data) {
    return fetch({
        url: '/api/cultureservice/minorCourse/queryCourse',
        method: 'POST',
        data
    });
}

/**
 * 课程信息导出
 */
export function exportCourseList(params) {
    let url = '/api/cultureservice/minorCourse/exportCourseList';
    let query = '?';
    for (let key in params) {
        query += key;
        query += '=';
        query += params[key];
        query += '&';
    }
    return url + query.substring(0, query.length - 1);
}

// 自动生成课程code
export function autoCode(data) {
    return fetch({
        url: 'api/cultureservice/minorCourse/code',
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        data
    });
}

/**
 * 查询启用状态的部门树(不包含虚拟部门)
 * @param {data} data
 */
export function findDept() {
    return fetch({
        url: '/api/userservice/dept/findDept?virtualDept=0',
        method: 'get'
    });
}

//查询课程分类
export function getClassifyList(data) {
    return fetch({
        url: '/api/cultureservice/classify/classifyList',
        method: 'post',
        data
    });
}

//新增课程分类

export function addClassify(data) {
    return fetch({
        url: '/api/cultureservice/classify/addClassify',
        method: 'post',
        data
    });
}

// 编辑课程分类
export function editClassify(data) {
    return fetch({
        url: '/api/cultureservice/classify/editClassify',
        method: 'put',
        data
    });
}

//删除课程分类
export function deleteClassify(data) {
    return fetch({
        url: '/api/cultureservice/classify/deleteClassify',
        method: 'delete',
        data
    });
}

//课程性质列表查询
export function getClassifyNature(id) {
    return fetch({
        url: `/api/cultureservice/classify/nature/${id}`,
        method: 'get'
    });
}

//新增课程性质
export function addMinorLable(data) {
    return fetch({
        url: '/api/cultureservice/classify/addMinorLable',
        method: 'POST',
        data
    });
}

//编辑课程性质
export function editMinorLable(data) {
    return fetch({
        url: '/api/cultureservice/classify/editMinorLable',
        method: 'POST',
        data
    });
}

//删除课程性质
export function delMinorLable(data) {
    return fetch({
        url: '/api/cultureservice/classify/delMinorLable',
        method: 'POST',
        data
    });
}

// 下载模板
export function downloadTemplate(data = {}) {
    let url = `/api/cultureservice/minorCourse/downloadTemplate`;
    window.open(url);
}

export default {
    downloadTemplate
};